/**
 * 生成压缩视频命令
 */

const path = require("path");
const ffmpegPath = path.join(__dirname , '../', 'ffmpeg', 'ffmpeg.exe');


function compress_video(filepath, savePath, bit, delAudio, fps, resolving_power) {

    bit = company(bit);
    fps = fps ? `-r ${fps}` : '';
    delAudio = delAudio ? '-an' : '';
    resolving_power = resolving_power ? `-filter:v scale=${resolving_power}` : '';

    let cmdStr = `"${ffmpegPath}" -i "${filepath}" ${delAudio} ${fps} ${bit} ${resolving_power} "${savePath}"`;

    return cmdStr;
}

// 秒转时分秒
function company(bit) {

    if (/\k$/.test(bit)) {
        return `-b ${bit}`;
    } else if (/^\d+$/.test(bit)) {
        return `-b ${bit}k`
    } else {
        return ''
    }

}

module.exports = compress_video;